package cn.zyy.hotel.controller;

import cn.zyy.hotel.entity.Room;
import cn.zyy.hotel.entity.RoomType;
import cn.zyy.hotel.service.RoomService;
import cn.zyy.hotel.service.RoomTypeService;
import cn.zyy.hotel.vo.RoomVO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/room")
public class RoomController {

    @Resource
    private RoomService roomService;

    @Resource
    private RoomTypeService roomTypeService;

    //查询房间详情
    @RequestMapping("/{id}.html")
    public String detail(@PathVariable Integer id, Model model){
        //调用查询房间详情的方法
        Room room = roomService.selectById(id);
        //将数据放到模型中
        model.addAttribute("room",room);
        return "detail";
    }

    //查询全部房间列表
    @RequestMapping("/list.html")
    public String list(Model model){
        //调用查询所有房型列表的方法
        List<RoomType> roomTypeList = roomTypeService.selectRoomTypeList(null);
        //创建查询条件类
        RoomVO roomVO = new RoomVO();
        roomVO.setStatus(3);//可预订
        //查询房间列表
        List<Room> roomList = roomService.selectRoomListByPage(roomVO);
        //将数据放到模型中
        model.addAttribute("roomTypeList",roomTypeList);
        model.addAttribute("roomList",roomList);
        return "hotelList";
    }

    //查询全部房间列表
    @RequestMapping("/list/{id}")
    public String list(@PathVariable Integer id, Model model){
        //调用查询所有房型列表的方法
        List<RoomType> roomTypeList = roomTypeService.selectRoomTypeList(null);
        //创建查询条件类
        RoomVO roomVO = new RoomVO();
        roomVO.setRoomTypeId(id);//房型ID
        roomVO.setStatus(3);//可预订
        //查询房间列表
        List<Room> roomList = roomService.selectRoomListByPage(roomVO);
        //将数据放到模型中
        model.addAttribute("roomTypeList",roomTypeList);
        model.addAttribute("roomList",roomList);
        //将当前选中的房型id回显
        model.addAttribute("typeId",id);
        return "hotelList";
    }



}
